package com.dragon.client.controller.auth;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dragon.common.model.Insert;
import com.dragon.common.model.ResponseData;
import com.dragon.logical.service.auth.TeamService;
import com.dragon.repository.domain.dto.TeamDTO;
import com.dragon.repository.domain.vo.TeamVO;
import com.dragon.repository.entity.Team;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author sy
 * @since 2023-06-28
 */
@RestController
@Api(tags = "团队成员管理")
@RequestMapping("team")
public class TeamController {

    @Autowired
    TeamService service;

    @GetMapping("teamList")
    @ApiOperation("团队成员列表")
    public ResponseData<List<TeamDTO>> teamList(@ApiParam(name = "id", value = "项目id", required = true, type = "int") @RequestParam Integer id){
        Page<Team> teamPage = service.teamList(id);
        return ResponseData.success(TeamDTO.convertList(teamPage.getRecords()),teamPage.getTotal());
    }

    @PostMapping("add")
    @ApiOperation("添加团队成员")
    public ResponseData addTeam(@RequestBody @Validated(Insert.class) TeamVO vo){
        service.add(TeamVO.convert(vo));
        return ResponseData.success();
    }

    @PostMapping("delete")
    @ApiOperation("删除团队成员")
    public ResponseData deleteTeam( @ApiParam(name = " id", value = "团队成员id", required = true , type = "int") Integer id){
        service.delete(id);
        return ResponseData.success();
    }

}
